using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace GempGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class MouseCursor : Microsoft.Xna.Framework.GameComponent
    {
        SpriteBatch spriteBatch;

        Boolean mousePressed;
        Texture2D m_mouseTexture;
        Texture2D m_mousePressedTexture;
        Vector2 m_mousePos;

        public MouseCursor(Game game)
            : base(game)
        {
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            mousePressed = false;
            m_mousePos = Vector2.Zero;

            base.Initialize();
        }

        public void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            m_mouseTexture = Game.Content.Load<Texture2D>("cursor");
            m_mousePressedTexture = Game.Content.Load<Texture2D>("cursorPressed");
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            MouseState mouseState = Mouse.GetState();
            m_mousePos.X = mouseState.X;
            m_mousePos.Y = mouseState.Y;

            if (mouseState.LeftButton == ButtonState.Pressed)
                mousePressed = true;
            else
                mousePressed = false;

            base.Update(gameTime);
        }



        public void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            // draw cursor

            if (!mousePressed)
                spriteBatch.Draw(m_mouseTexture, m_mousePos, null, Color.CornflowerBlue, 0f,
                Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
            else
                spriteBatch.Draw(m_mousePressedTexture, m_mousePos, null, Color.CornflowerBlue, 0f,
                Vector2.Zero, 1.0f, SpriteEffects.None, 0f);

            spriteBatch.End();
        }
    }
}
